package com.mingqi.enetconnected.primary.mytask.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.util.resource.ResourceUtils;

import java.util.List;

/**
 * Created by li on 2018/8/10.
 * WeChat 18571658038
 * author LiWei
 */

public class BusinessTypeAdapter extends BaseAdapter {

    @Nullable
    private List<String> mData;

    public BusinessTypeAdapter(@Nullable List<String> data) {
        mData = data;
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        TypeHolder th;
        if(convertView == null) {

            convertView = ResourceUtils.getViewFollowParent(R.layout.item_business_type,parent);
            th = new TypeHolder();

            th.tvBusinessType = convertView.findViewById(R.id.tv_business_type);
            convertView.setTag(th);
        } else {

            th = (TypeHolder) convertView.getTag();
        }

        th.tvBusinessType.setText(mData.get(position));
        return convertView;
    }

    static class TypeHolder{

        TextView tvBusinessType;
    }
}
